package com.hzw.saas.service.old.storage.service;


import com.hzw.saas.api.old.storage.ICatalogService;
import com.hzw.saas.api.old.storage.constants.StorageConstants;
import com.hzw.saas.service.old.hub.util.StorageUtil;
import cn.hutool.core.util.ArrayUtil;
import org.springframework.stereotype.Service;

/**
 * @author zzl
 * @since 04/24/2021
 */
@Service
public class OldCatalogServiceImpl implements ICatalogService {

    @Override
    public String getPath(String catalog, String... subPaths) {
        String root = catalog;
        if (subPaths.length == 0)
            return root;
        String[] paths = ArrayUtil.insert(subPaths, 0, root);
        return StorageUtil.connectPath(paths);
    }

    @Override
    public String getFileParentPath(String catalog) {
        String root = catalog;
        root = StorageUtil.connectPath(root, StorageConstants.STORAGE_FILE_ROOT);
        return root;
    }

    @Override
    public String getFilePath(String catalog, String... subPaths) {
        String root = catalog;
        root = StorageUtil.connectPath(root, StorageConstants.STORAGE_FILE_ROOT);
        if (subPaths.length == 0)
            return root;
        String[] paths = ArrayUtil.insert(subPaths, 0, root);
        return StorageUtil.connectPath(paths);
    }

    @Override
    public String getCachePath(String catalog, String... subPaths) {
        String root = catalog;
        root = StorageUtil.connectPath(root, StorageConstants.STORAGE_CACHE_ROOT);
        if (subPaths.length == 0)
            return root;
        String[] paths = ArrayUtil.insert(subPaths, 0, root);
        return StorageUtil.connectPath(paths);
    }
}
